
import java.awt.*;
import javax.swing.*;

public class AVL {

	public static void main(String[] args) {
		
		bubblesort();
		
		boolean aa = false;
		if(aa){
		
		AVLGUI gui = new AVLGUI("test.src");
		
		
		AVLBasicType a = new AVLBasicType("a", 10);
		AVLBasicType b = new AVLBasicType("b", 20);
		AVLBasicType c = new AVLBasicType("c", 30);
		AVLBasicType d = new AVLBasicType("d", 40);
		
		gui.watch(a);
		gui.watch(b);
		gui.watch(c);
		gui.watch(d);
		
		
		AVLBasicType[] arr = {a, b, c, a, a, a ,a, a, a, a};
		AVLBasicType[] arr2 = {a, b, c, d};
		AVLArray avlarr = new AVLArray("array", arr);
		AVLArray avlarr2 = new AVLArray("array2", arr2);
		gui.watch(avlarr);
		gui.watch(avlarr2);
		
		AVLBasicType[][] mat = {{a, b, c}, {a, b, c}, { b, c, d}};
		AVLBasicType[][] mat2 = {{a, b, c}, {b, c, a}};
		mat2[0][1] = d;
		AVLMatrix avlmar = new AVLMatrix("matrix", mat);
		AVLMatrix avlmar2 = new AVLMatrix("matrix2", mat2);
		AVLMatrix avlmar3 = new AVLMatrix("matrix3", mat2);
		gui.watch(avlmar);
		gui.watch(avlmar2);
		gui.watch(avlmar3);
		
		
		
		gui.block();
		
		a.set(100);
		gui.highlightSourceLine(2, false);
		gui.highlightSourceLine(1, true);
		gui.highlightSourceLine(4);
		
		gui.block();
		
		a.reset();
		avlarr.set(0, (Integer)a.get() + (Integer)b.get());
		//gui.clearSourceLineHighlights();
		
		gui.resetAll();
		}
		
		
		
	}
	
	public static void bubblesort() {
		
		AVLGUI gui = new AVLGUI("bubble.src");
		
		AVLBasicType a = new AVLBasicType("0", 11);
		AVLBasicType b = new AVLBasicType("1", 24);
		AVLBasicType c = new AVLBasicType("2", 32);
		AVLBasicType d = new AVLBasicType("3", 47);
		AVLBasicType e = new AVLBasicType("4", 15);
		AVLBasicType f = new AVLBasicType("5", 23);
		AVLBasicType g = new AVLBasicType("6", 37);
		AVLBasicType h = new AVLBasicType("7", 48);
		
		AVLBasicType[] arr = {a, b, c, d, e, f, g, h};
		
		AVLArray aa = new AVLArray("array", arr);
		
		
		gui.watch(aa);
		boolean btemp;
		
		//boolean swapped = true;
		AVLBasicType swapped = new AVLBasicType("swapped", false);
		gui.watch(swapped);
		
		
		gui.block();
		
		do {
			swapped.set(false);
			gui.highlightSourceLine(3);
			gui.block();
			gui.resetAll();
			gui.block();
			
			for(int i = 1; i < arr.length; i++) {
				btemp = (Integer)aa.get(i-1) > (Integer)aa.get(i);
				gui.highlightSourceLine(5, btemp);
				gui.block();
				gui.resetAll();
				gui.block();
				
				if(btemp) {
					int temp = (Integer)aa.get(i-1);
					aa.set(i-1, aa.get(i));
					aa.set(i, temp);
					gui.highlightSourceLine(6);
					gui.block();
					gui.resetAll();
					gui.block();
					
					gui.highlightSourceLine(7);
					swapped.set(true);
					gui.block();
					gui.resetAll();
					gui.block();
				}
			}
			
			btemp = (Boolean)swapped.get();
			gui.highlightSourceLine(10, btemp);
			gui.block();
			gui.resetAll();
			gui.block();
		}
		while(btemp);
		
		gui.watch(new AVLBasicType("done!", true));
		
		
	}
}
